package com.golxen.framework.common.server.game.cmd;


import com.golxen.framework.PBPacket.PBPacket;
import com.google.protobuf.Message;
import io.netty.channel.ChannelHandlerContext;

public abstract class AbstractServerCommand implements Command {

    /**
     * 结果值
     */
    protected int ret = 0;

    public Tuple execute(ChannelHandlerContext ctx, PBPacket packet) throws Exception {
        Message msg = null;
        Throwable ex = null;
        try {
            msg = parseData(packet);
            execute(packet);
            sendData(packet);
        } catch (Throwable e) {
            ex = e;
        }
        return new Tuple(ex, msg);
    }

    public abstract Message parseData(PBPacket packet) throws Exception;

    public abstract void execute(PBPacket packet) throws Exception;

    public abstract void sendData(PBPacket packet) throws Exception;
}
